<template>
<div>
  <div class="mainechart">
    <div id="topleft"></div>  
    <div id="topright"></div>
    <div id="downleft"></div>
    <div id="downright"></div>
    </div>
  </div>
</template>
 
<script>

import echarts from "echarts";
import API from "@/api/myechart";
import axios from 'axios';
const {
topleftmethod,

} = API;
export default {
  name: 'MyEchart',
  mounted() {
    this.topleftmethod();
    this.toprightmethod();
    this.downleftmethod();
    this.downrightmethod();
  },
  data() {
     return{
      
      } 
  },
  methods: {
    topleftmethod(){

        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('topleft'));
       
         axios(
              {
                        method: "POST",
                        url: topleftmethod,
                        headers: {
                            'Content-Type': 'application/json;charset=UTF-8',  //指定消息格式
                        },
               }
           )
          .then(res => {
            
              console.log(res.data)
                   
          }, res => {
            // 错误回调
                    console.log("222")
          })
       

        // 指定图表的配置项和数据
        var option1 = {
                    title : {
                        text: '收入管理'
                    },
                    color: [ '#91c7ae','#749f83',  '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'],
                    tooltip : {
                        trigger: 'axis'
                    },
                    legend: {
                        data:['个人收入','家庭收入']
                    },
                    toolbox: {
                        show : true,
                        feature : {
                            dataView : {show: true, readOnly: false},
                            magicType : {show: true, type: ['line', 'bar']},
                            restore : {show: true},
                            saveAsImage : {show: true}
                        }
                    },
                    calculable : true,
                    xAxis : [
                        {
                            type : 'category',
                            data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
                        }
                    ],
                    yAxis : [
                        {
                            type : 'value'
                        }
                    ],
                    series : [
                        {
                            name:'个人收入',
                            type:'bar',
                            data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
                            markPoint : {
                                data : [
                                    {type : 'max', name: '最大值'},
                                    {type : 'min', name: '最小值'}
                                ]
                            },
                            markLine : {
                                data : [
                                    {type : 'average', name: '平均值'}
                                ]
                            }
                        },
                        {
                            name:'家庭收入',
                            type:'bar',
                            data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
                            markPoint : {
                                data : [
                                    {name : '年最高', value : 182.2, xAxis: 7, yAxis: 183},
                                    {name : '年最低', value : 2.3, xAxis: 11, yAxis: 3}
                                ]
                            },
                            markLine : {
                                data : [
                                    {type : 'average', name : '平均值'}
                                ]
                            }
                        }
                    ]
                };

     
       
      

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option1);
       
     
    },
    toprightmethod(){
        var myChart1 = echarts.init(document.getElementById('topright'));
           // 指定图表的配置项和数据
        var option2 = {
            title: {
                text: '负债统计'
            },
            tooltip: {},
            legend: {
                data:['元']
            },
            xAxis: {
                data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        };
            myChart1.setOption(option2);
    },
    downleftmethod(){
       var myChart2 = echarts.init(document.getElementById('downleft'));
        // 指定图表的配置项和数据
        var option3 = {
                  title: {
                      text: '还款折线图'
                  },
                  tooltip: {
                      trigger: 'axis'
                  },
                  legend: {
                      data:['还款折线图']
                  },
                  grid: {
                      left: '3%',
                      right: '4%',
                      bottom: '3%',
                      containLabel: true
                  },
                  toolbox: {
                      feature: {
                          saveAsImage: {}
                      }
                  },
                  xAxis: {
                      type: 'category',
                      boundaryGap: false,
                      data: ['周一','周二','周三','周四','周五','周六','周日']
                  },
                  yAxis: {
                      type: 'value'
                  },
                  series: [
                      {
                          name:'还款折线图',
                          type:'line',
                          stack: '总量',
                          data:[120, 132, 101, 134, 90, 230, 210]
                      }
                  ]
              };
      myChart2.setOption(option3);
    },
    downrightmethod(){
          var myChart3 = echarts.init(document.getElementById('downright'));
            // 指定图表的配置项和数据
        var option4 = {
             title : {
                    text: '负债率',
                    subtext: '纯属虚构',
                    x:'center'
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['直接访问','邮件营销']
                },
                series : [
                    {
                        name: '访问来源',
                        type: 'pie',
                        radius : '55%',
                        center: ['50%', '60%'],
                        data:[
                            {value:335, name:'直接访问'},
                            {value:310, name:'邮件营销'}
                           
                        ],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
        };

        myChart3.setOption(option4);
    }
  }
};
</script>

<style scoped>
.mainechart{
  position: relative;
  width: 600px;
  height: 800px;
}
#topleft{
    width: 600px;
    height: 400px;
    position: relative;
    left: 0px;
    top: 0px;
}
#topright{
    width: 600px;
    height: 400px;
    position: absolute;
    left: 800px;
    top: 0px;
}
#downleft{
    width: 600px;
    height: 400px;
    position: absolute;
    top: 400px;
    left: 0px;
}
#downright{
    width: 600px;
    height: 400px;
    position: absolute;
    left: 800px;
    top: 400px;
}
</style>
